var centerVersionJs = function(targetObj) {
	this.targetObj = targetObj;
	this.sysUtils = new kendoUtils();
	this.init();
	return this;
}
centerVersionJs.prototype = {
		init : function() {
			var fieldArray = this.sysUtils.getBindFieldArray(this.targetObj);
			var functionArray = [{fName:"queryInfo", fs:this.findGridData},
			                     {fName:"resetInfo",fs:this.resetInfo}
			];
			this.models = new bindBaseModel(null, fieldArray, functionArray, null);
			this.sysUtils.bindDoucment(this.models, this.targetObj, this);
			//初始化配置界面
			this.loadHtml();
			this.createGrid();
			//加载升级方式   默认安全更新
			Utils.createDataDictDropDownList({ div:this.targetObj.find("#updateStatus"),parentModelKey: BASIS.UPGRADE_STATUS.ROOT},this);
		},
		loadHtml:function(){
			var that = this;
			//加载版本列表
			JsonpAjax(baseApiPath + "largeFileUpoad/findVersionList",null, 'json', function(res) {
				if(isEmpty(res)) return;
				var versionList = that.targetObj.find("#versionList");
				versionList.empty();
				var versionInfo = that.targetObj.find("#templateDiv").find("div[name='versionInfo']");
				var version = null;
				//循环添加版本信息
				for(var i = 0;i<res.length;i++){
					version = versionInfo.clone();
					version.find("span[name='versionNumber']").html(res[i]["versionNumber"]);
					version.find("span[name='versionSize']").html(res[i]["fileSize"] + "(MB)");
					version.find("span[name='checkCode']").html(res[i]["checkCode"]);
					version.find("span[name='releaseTime']").html(res[i]["releaseTime"]);
					version.find("span[name='uploadUserName']").html(res[i]["uploadUserName"]);
					version.find("span[name='uploadTime']").html(res[i]["uploadTime"]);
					version.data("json",res[i]);
					version.find(".active").bind("click",that.clickChange);
					versionList.append(version);
				}
			});
		},
		resetInfo:function(e){
			var that = $(e.target).data("that");
			that.sysUtils.setBindFieldNull(that.models.bindFieldArray);
		},
		findGridData:function(e,parentModelKey){
			var that = this;
			if(isNotEmpt(e)){
				that = $(e.target).data("that");
			}
			if(validityForm(that.targetObj)){
				debugger;
				var jsonObj = that.sysUtils.getBindDocJson();
				var kendoGrid  = that.targetObj.find("#monitorUpdateGrid").data("kendoGrid");
				var urls = baseApiPath +"largeFileUpoad/findUpdateByPage";
				var dataT = {curdatetime:new Date().getTime(),json:JSON.stringify(jsonObj)};
				var dataSource = that.sysUtils.getDataSource({url:urls,data:dataT,dataType:"odata"});
				kendoGrid.setDataSource(dataSource); 
			}
		},
		/*
		 * 创建空列表
		 */
		createGrid:function(){
			var columns = this.gridColumns();
			var that = this;
			this.sysUtils.createGird(this.targetObj.find("#monitorUpdateGrid"), {
				dataSource:[],
				selectable: "single",
				reorderable: true,
				columnMenu: true,
				resizable: true,
				pageable: {input: true,
					numeric: false},
					columns: columns
			});
		},
		/**
		 * 选中行
		 */
		selectRow:function(){
			var grid = this.targetObj.find("#monitorUpdateGrid").data("kendoGrid");
			var dataItem = grid.dataItem(grid.select());
			if(isEmpty(dataItem)){
				return null;
			}
			var id = dataItem["id"];
			return id;
		},
		/*
		 * 加载list 列表
		 */
		gridColumns:function(){
			return [{
				title: "工作站名称",
				template:"#:workstationName#(#:workstationCode#)",
				width:"250px"
			},{
				title: "升级版本",
				field:"updateVersion"
			},{
				title: "升级方式",
				template : '#:Utils.getModelNameByParentKey(BASIS.UPGRADE_METHODS.ROOT,  data.updateMethod == null ? "" : data.updateMethod)#'
			},{
				title: "升级时间",
				field: "updateTime"
			},{
				title: "升级状态",
				template : '#:Utils.getModelNameByParentKey(BASIS.UPGRADE_STATUS.ROOT,  data.updateStatus == null ? "" : data.updateStatus)#'
			},{
				title: "升级完成时间",
				field:"updateCompletionTime"
			},{
				title: "操作人",
				field:"createUserName"
			},{
				title: "操作时间",
				field:"createTime"
			}];
		},
		/**
		 * 改变选中状态
		 */
		clickChange:function(e){
			var versionInfo = $(this).parent("div[name='versionInfo']");
			versionInfo.addClass("active");
			versionInfo.siblings().removeClass("active");
		},
		/**
		 * 下载版本文件
		 */
		downLoadVersion:function(){
			var versionInfo = this.targetObj.find("div.active[name='versionInfo']");
			if(versionInfo.length <= 0){
				notification({title : '提示', message : '请在版本列表中选择需要下载的版本文件！！'}, 'info');
				return;
			}
			var version = versionInfo.data("json");
			var downloadUrl = version["downloadUrl"];
			if(isEmpty(downloadUrl)){
				notification({title : '提示', message : '未找到可用的下载地址！！'}, 'info');
				return;
			}
			window.open(imgServerUrl+"/"+version["downloadUrl"]);
		},
		/**
		 * 打开添加版本升级窗口
		 */
		addUpdateVersionInfo:function(){
			this.addVersion = this.sysUtils.openWindow(this.addVersion,{
				title:"添加工作站版本升级任务",
				height:"600px",
				width:"850px",
				resizable:false,
				content:"views/parkLotCenter/SystemConfigManager/addUpgradeTask.html"
			}, true);
		},
		/**
		 * 上传版本文件
		 */
		uploadVersionFile:function(){
			this.uploadVersion = this.sysUtils.openWindow(this.uploadVersion,{
				title:"上传升级版本文件",
				height:"280px",
				width:"530px",
				resizable:false,
				content:"views/parkLotCenter/SystemConfigManager/VsersionUpload.html"
			}, true);
		}


}